//
//  Utils.swift
//  yundcmHD
//
//  Created by qmsoft_macmini on 16/2/22.
//  Copyright © 2016年 qmsoft_macmini. All rights reserved.
//

import Foundation
import UIKit

class Utils: NSObject {
    
    /**获取设备的物理高度 */
    static func screenHeight()->CGFloat {
        let main = UIScreen.mainScreen()
        let rect = main.bounds
        let height = rect.height
        return height
    }
    
    /**获取设备的物理宽度*/
    static func screenWidth()->CGFloat {
        let main = UIScreen.mainScreen()
        let rect = main.bounds
        let width = rect.width
        return width
    }
    
    
    /**根据输入的天数获取最近天数日期*/
    static func getDataRange(day:NSTimeInterval) ->String {
        let startDate = NSDate().dateByAddingTimeInterval(-3600 * 24 * day)
        let dateForm = NSDateFormatter()
        dateForm.locale = NSLocale(localeIdentifier: "zh_CN")
        dateForm.dateFormat = "yyyy-MM-dd"
        return dateForm.stringFromDate(startDate)
    }
    
    /**获取当前日期*/
    static func getNowDate() -> String {
        let now = NSDate()
        let dateForm = NSDateFormatter()
        dateForm.locale = NSLocale(localeIdentifier: "zh_CN")
        dateForm.dateFormat = "yyyy-MM-dd"
        return dateForm.stringFromDate(now)
    }
    
    /**获取当前日期时间*/
    static func getNowDateTime() -> String {
        let now = NSDate()
        let dateForm = NSDateFormatter()
        dateForm.locale = NSLocale(localeIdentifier: "zh_CN")
        dateForm.dateFormat = "yyyy-MM-dd HH:mm:ss"
        return dateForm.stringFromDate(now)
    }
    
    /**时差*/
    static func getTimeDifference(dateTime: String) -> Int {
        let dateFormatter = NSDateFormatter()
        dateFormatter.locale = NSLocale(localeIdentifier: "zh_CN")
        dateFormatter.setLocalizedDateFormatFromTemplate("yyyy-MM-dd HH:mm:ss")
        if let date = dateFormatter.dateFromString(dateTime) {
            let delta = NSDate().timeIntervalSinceDate(date)
            return Int(delta)
        } else {
            return 0
        }
    }

}

